package net.huashitong.zhApp.controller;

import com.sirdc.modules.core.filter.Paging;
import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.Project.filter.EarlyWarningNodeFilter;
import net.huashitong.oversee.databean.DepartRank;
import net.huashitong.oversee.entity.GradePoint;
import net.huashitong.oversee.entity.ScoreSummary;
import net.huashitong.oversee.filter.GradePointFilter;
import net.huashitong.oversee.filter.ScoreSummaryFilter;
import net.huashitong.oversee.service.GradePointService;
import net.huashitong.oversee.service.ScoreSummaryService;
import net.huashitong.user.entity.BnpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/zhApp/scoreSummary")
public class AppScoreSummaryController extends BaseCtrl {

    @Autowired
    private ScoreSummaryService service;
    @Autowired
    private GradePointService gradePointService;


    @ResponseBody
    @RequestMapping(value = "/lists",method = RequestMethod.POST)
    public Map<String, Object> scoreSummaryList(@RequestBody ScoreSummaryFilter filter) {

        if (filter.isDepartRank()) {
            if (StringUtils.isNotBlank(filter.getPaging().getSortVal())) {
                filter.getPaging().setSortVal("");
            }
            List<DepartRank> list = service.queryDepartRank(filter);
            int num = (filter.getPaging().getCurrentPage() - 1) * 10 + 1;
            for (DepartRank d : list) {
                double x = (double) Math.round(d.getScore() * 100) / 100;
                d.setScore(x);
                d.setRank(num + "");
                d.setCheckDept("——");
                num++;
            }

            Map<String, Object> result = new HashMap<>();
            result.put("code", "200");
            result.put("message", "成功获取数据");
            result.put("data", list);

            return result;
        }
        List<ScoreSummary> list = service.queryByFilter(filter);
        if (StringUtils.isBlank(filter.getBranchType())) {
            Map<String, Object> result = new HashMap<>();
            result.put("code", "200");
            result.put("message", "成功获取数据");
            result.put("data", list);
            result.put("count", filter.getPaging().getRecords());
            return result;

        } else {
            for (ScoreSummary summary : list) {
                summary.setRank(summary.getTypeRank());
            }
            Map<String, Object> result = new HashMap<>();
            result.put("code", "200");
            result.put("message", "成功获取数据");
            result.put("data", list);
            result.put("count", filter.getPaging().getRecords());
            return result;
        }
    }


    @ResponseBody
    @RequestMapping(value = "/queryGradePointDetailByCheckObjectId", method = RequestMethod.POST)
    public Message queryGradePointDetailByCheckObjectId(@RequestBody GradePointFilter filter) {
        Paging paging = new Paging();
        paging.setSortVal("createDate");
        paging.setSortCol("desc");
        List<GradePoint> lists = gradePointService.queryGradePoint(filter);
        Message message = new Message();
        message.setCode("200");
        message.setMessage("成功获取考核记录");
        message.setData(lists);
        return message;
    }
}
